package bu.met.cs664;

import java.util.Scanner;

/**
 * A player that uses text input to move.
 */
public class HumanPlayer extends Player {
	Scanner in;

	/**
	 * Constructor
	 * 
	 * @param position	The square where the player is originally placed
	 */
	public HumanPlayer(int[] position) {
		super(position);
		
		in = new Scanner(System.in);
	}

	@Override
	public Actions getAction(String attributes) {
		String sense = "nothing";
		
		if (attributes.toLowerCase().contains("b")) {
			sense = "a breeze";
		}
		if (attributes.toLowerCase().contains("g")) {
			if (sense.contains("nothing")) {
				sense = "a glitter";
			} else {
				sense = sense.concat(" and a glitter");		
			}
		}
		if (attributes.toLowerCase().contains("s")) {
			if (sense.contains("nothing")) {
				sense = "a stench";
			} else {
				sense = sense.concat(" and a stench");		
			}
		}
		if (attributes.toLowerCase().contains("m")) {
			if (sense.contains("nothing")) {
				sense = "a scream";
			} else {
				sense = sense.concat(" and a scream");		
			}
		}
		
		if (attributes.toLowerCase().contains("w")) {
			System.out.println("Player gets killed by a Wumpus.");
		} else if (attributes.toLowerCase().contains("p")) {
			System.out.println("Player falls in a pit and dies.");
		} else {
			System.out.println("Player senses " + sense + ".");
		}
		
		while (true) {
			System.out.println("Where do you want to go? [wasdijklp]");
			String input = in.nextLine();
			if (input.length() > 0) {
				char key = input.toLowerCase().charAt(0);
				
				switch (key) {
					case 'w':
						return Actions.MOVE_NORTH;
					case 'a':
						return Actions.MOVE_WEST;
					case 's':
						return Actions.MOVE_SOUTH;
					case 'd':
						return Actions.MOVE_EAST;
					case 'i':
						return Actions.SHOOT_NORTH;
					case 'j':
						return Actions.SHOOT_WEST;
					case 'k':
						return Actions.SHOOT_SOUTH;
					case 'l':
						return Actions.SHOOT_EAST;
					case 'p':
						return Actions.PICK_UP_GOLD;	
				}
			}
		}
	}

}
